using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AlphaWebsite.Models;

namespace AlphaWebsite.Controllers
{   
    public class CityDistrictsController : Controller
    {
		private readonly ICityDistrictRepository citydistrictRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public CityDistrictsController() : this(new CityDistrictRepository())
        {
        }

        public CityDistrictsController(ICityDistrictRepository citydistrictRepository)
        {
			this.citydistrictRepository = citydistrictRepository;
        }

        //
        // GET: /CityDistricts/

        public ViewResult Index()
        {
            return View(citydistrictRepository.All);
        }

        //
        // GET: /CityDistricts/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(citydistrictRepository.Find(id));
        }

        //
        // GET: /CityDistricts/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /CityDistricts/Create

        [HttpPost]
        public ActionResult Create(CityDistrict citydistrict)
        {
            if (ModelState.IsValid) {
                citydistrictRepository.InsertOrUpdate(citydistrict);
                citydistrictRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /CityDistricts/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
             return View(citydistrictRepository.Find(id));
        }

        //
        // POST: /CityDistricts/Edit/5

        [HttpPost]
        public ActionResult Edit(CityDistrict citydistrict)
        {
            if (ModelState.IsValid) {
                citydistrictRepository.InsertOrUpdate(citydistrict);
                citydistrictRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /CityDistricts/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(citydistrictRepository.Find(id));
        }

        //
        // POST: /CityDistricts/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            citydistrictRepository.Delete(id);
            citydistrictRepository.Save();

            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                citydistrictRepository.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}

